import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/services.dart';
import 'package:system_boot_time_ohos/system_boot_time_ohos.dart';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();
  group('SystemBootTime', () {
    final MethodChannel channel = MethodChannel('system_boot_time_ohos');
    setUp(() {
      channel.setMockMethodCallHandler((MethodCall methodCall) async {
        return {'result': 1234567890};
      });
    });
    tearDown(() {
      channel.setMockMethodCallHandler(null);
    });

    test('second method should throw PlatformException on error', () async {
      channel.setMockMethodCallHandler((MethodCall methodCall) async {
        return {
          'error': {'code': 'channel-error', 'message': 'Mock error'}
        };
      });

      final SystemBootTime systemBootTime = SystemBootTime();
      final Future<int> future = systemBootTime.second();
      expect(future, throwsA(isA<PlatformException>()));
    });

    test('second method should throw PlatformException when null is returned',
        () async {
      channel.setMockMethodCallHandler((MethodCall methodCall) async {
        return null;
      });
      final SystemBootTime systemBootTime = SystemBootTime();
      final Future<int> future = systemBootTime.second();
      expect(future, throwsA(isA<PlatformException>()));
    });
  });
}
